import 'package:hrf_app/common/services/user.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:tdesign_flutter/tdesign_flutter.dart';

import 'index.dart';

class MainMyTabPage extends GetView<MainMyTabController> {
  const MainMyTabPage({super.key});

  Widget _buildAvatar() {
    return Container(
        padding: EdgeInsets.all(10),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Row(
              children: [
                TDAvatar(
                  size: TDAvatarSize.medium,
                  type: TDAvatarType.normal,
                  avatarUrl: UserService.to.profile.avatar!,
                ),
                SizedBox(
                  width: 2,
                ),
                TDText(UserService.to.profile.nickname??""),
              ],
            ),
            Row(
              children: [
                TDButton(
                  text: "详情",
                  size: TDButtonSize.small,
                  type: TDButtonType.text,
                )
              ],
            )
          ],
        ));
  }

  Widget _buildLoginOut() {
    return Center(
        child: TDButton(
      size: TDButtonSize.large,
      type: TDButtonType.fill,
      theme: TDButtonTheme.primary,
      onTap: () {
        controller.loginOut();
      },
      text: '退出',
    ));
  }

  // 主视图
  Widget _buildView() {
    return Column(
      children: [_buildAvatar(), _buildLoginOut()],
    );
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<MainMyTabController>(
      init: MainMyTabController(),
      id: "main_my",
      builder: (_) {
        return Scaffold(
          body: SafeArea(
            child: _buildView(),
          ),
        );
      },
    );
  }
}
